#ifndef FILEOPERATION_H
#define FILEOPERATION_H
#include "cipherfactory.h"
#include <QByteArray>
#include <QFile>
#include <QDir>
#include <QIODevice>
#include <QFileInfo>
#include <QFileInfoList>
#include <QRegExp>
#include <QObject>

class FileOperation : public QObject
{
    Q_OBJECT

Q_SIGNALS:
  void sendPro(double progress);

private:
  QStringList srcPathList;
  QStringList filePathList;
  QStringList emptyFolder;
  QString srcPath;
  QString desPath;
  CCipherFactory cipherFactory;

public:
  FileOperation();
  FileOperation(QStringList srcPathList, QString desPath);
  FileOperation(QString srcPath, QString desPath);
  bool validatePassword(QString password, QByteArray hashCode);
  /**
   * @param algorithm 加密算法对应的key
   * @param mode 加密模式对应的key
   * @param password 密钥字符串
   *
   * @return 0 加密成功; 1 不存在的地址；2 加密文件出错
   */
  int handleFileEncryption(int algorithm, int mode, QString password);
  /**
   * @param password 密钥字符串
   *
   * @return 0 解密成功；1 不存在的地址；2 密码错误；3 文件结构被破坏；4 解密文件出错
   */
  int handleFileDecryption(QString password);
  void analyzeFile();
  void handleDir(QString dir);
  void createDir(QString path);
  QByteArray int2Byte(int);
  int byte2Int(QByteArray);
  QByteArray handleHash(QByteArray data);
  void deleteAllFiles(QStringList fileList);
  void deleteAllDirs(QStringList dirList);

  static bool isEncryptFile(QString srcPath);
  static bool isFileExist(QString path);
};

#endif // FILEOPERATION_H
